package com.atwisdom.star.core.dao.pojo.modelClass;

import com.alibaba.fastjson.JSONObject;
import com.atwisdom.star.common.typeHandler.MyFastjsonTypeHandler;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
public class BaseTable implements Serializable {

    /**
     * 模型标识
     */
    @TableId(value = "id", type = IdType.AUTO)
    public Long id;

    /**
     * 实体模型类型
     */
    @TableField(value = "type")
    public String type;

    /**
     * 横型类名称
     */
    @TableField(value = "className")
    public String className;

    /**
     * 版本号
     */
    @TableField(value = "version")
    public BigDecimal version;

    /**
     * web 相关信息
     */
    @TableField(value = "web", typeHandler = MyFastjsonTypeHandler.class)
    public JSONObject web;

    /**
     * 其它属性
     */
    @TableField(value = "others", typeHandler = FastjsonTypeHandler.class)
    public JSONObject others;

    /**
     * 是否发布
     */
    @TableField(value = "published")
    public Boolean published;

    /**
     * 说明
     */
    @TableField(value = "comments")
    public String comments;

    /**
     * 逻辑删除
     */
    @TableField(value = "deleteFlag")
    public Boolean deleteFlag;
    /**
     * 创建人账号
     */
    @TableField(value = "createdBy",fill = FieldFill.INSERT)
    public String createdBy;

    /**
     * 创建时间
     */
    @TableField(value = "createTime",fill = FieldFill.INSERT)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
    public LocalDateTime createTime;

    /**
     * 修改人账号
     */
    @TableField(value = "updatedBy",fill = FieldFill.INSERT_UPDATE)
    public String updatedBy;

    /**
     * 修改时间
     */
    @TableField(value = "updateTime",fill = FieldFill.INSERT_UPDATE)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
    public LocalDateTime updateTime;
}
